import request from '@/config/axios'

export interface PictureBookCreateReqVO {
  title: string
  description?: string
  cover?: string
  bookSetId: number
  sortOrder?: number
  isActive?: boolean
}

export interface PictureBookUpdateReqVO extends PictureBookCreateReqVO {
  id: number
}

export interface PictureBookAdminRespVO {
  id: number
  title: string
  description?: string
  cover?: string
  bookSetId: number
  sortOrder?: number
  pages: number
  isActive: boolean
  createTime: string
  updateTime: string
  creator?: string
  updater?: string
}

export interface PictureBookPageReqVO extends PageParam {
  title?: string
  bookSetId?: number
  isActive?: boolean
}

// 创建绘本
export const createPictureBook = (data: PictureBookCreateReqVO) => {
  return request.post({
    url: '/reading/admin/books/create',
    data
  })
}

// 更新绘本
export const updatePictureBook = (data: PictureBookUpdateReqVO) => {
  return request.put({
    url: '/reading/admin/books/update',
    data
  })
}

// 删除绘本
export const deletePictureBook = (id: number) => {
  return request.delete({
    url: '/reading/admin/books/delete',
    params: { id }
  })
}

// 获取绘本详情
export const getPictureBook = (id: number) => {
  return request.get({
    url: '/reading/admin/books/get',
    params: { id }
  })
}

// 获取绘本分页
export const getPictureBookPage = (params: PictureBookPageReqVO) => {
  return request.get({
    url: '/reading/admin/books/page',
    params
  })
}

// 根据绘本集ID获取绘本列表
export const getPictureBooksByBookSetId = (bookSetId: number) => {
  return request.get({
    url: '/reading/admin/books/list-by-book-set',
    params: { bookSetId }
  })
}

// 批量创建绘本
export const batchCreatePictureBooks = (data: PictureBookCreateReqVO[]) => {
  return request.post({
    url: '/reading/admin/books/batch-create',
    data
  })
}

// 获取下一个绘本ID
export const getNextPictureBookId = () => {
  return request.get({
    url: '/reading/admin/books/next-id'
  })
}

// 批量获取下一批绘本ID
export const getBatchNextPictureBookIds = (count: number) => {
  return request.get({
    url: '/reading/admin/books/batch-next-ids',
    params: { count }
  })
}
